/**
 * Copyright 2010 Creative Works, Inc.
 * Creative Works licenses this file to you under the Apache License, version
 * 2.0 (the "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *    http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied.  See the License for the specific language governing
 * permissions and limitations under the License.
 */
package org.sendvox.freswitch.event.impl;

import java.util.Date;

import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.sendvox.freswitch.event.Event;

/**
 * POJO containing the minimum amount of information sent for an event. That
 * information is always included, no matter which event it is.Most events do
 * not have a body but some do, such as the MESSAGE_WAITING event which contains
 * the protocol specific MWI data. Also the MESSAGE event contains the composed
 * text of the message much like an email.
 * 
 */
public abstract class BaseMessage implements Message {

	private static final long serialVersionUID = -1119729736841432018L;

	private Date dateReceived;
	private String coreUUID;
	private String freeSwitchHostname;
	private String freeSwitchSwitchname;
	private String freeSwitchIPv4;
	private String freeSwitchIPv6;
	private String eventDateLocal;
	private String eventDateGMT;
	private String eventDateTimestamp;
	private String eventCallingFile;
	private String eventCallingFunction;
	private Integer eventCallingLineNumber;

	public BaseMessage() {
		super();
		this.dateReceived = new Date();
	}

	/**
	 * The event's name, which is a description of the type of event it is
	 * 
	 * @return eventName
	 */
	public abstract Event getEventName();

	/**
	 * The UUID of the current instance of the FreeSWITCH core
	 * 
	 * @return coreUUID
	 */
	public String getCoreUUID() {
		return coreUUID;
	}

	/**
	 * Sets the UUID of the current instance of the FreeSWITCH core
	 * 
	 * @param coreUUID
	 */
	public void setCoreUUID(String coreUUID) {
		this.coreUUID = coreUUID;
	}

	/**
	 * @return the freeSwitchHostname
	 */
	public String getFreeSwitchHostname() {
		return freeSwitchHostname;
	}

	/**
	 * @param freeSwitchHostname
	 *            the freeSwitchHostname to set
	 */
	public void setFreeSwitchHostname(String freeSwitchHostname) {
		this.freeSwitchHostname = freeSwitchHostname;
	}

	/**
	 * @return the freeSwitchSwitchname
	 */
	public String getFreeSwitchSwitchname() {
		return freeSwitchSwitchname;
	}

	/**
	 * @param freeSwitchSwitchname
	 *            the freeSwitchSwitchname to set
	 */
	public void setFreeSwitchSwitchname(String freeSwitchSwitchname) {
		this.freeSwitchSwitchname = freeSwitchSwitchname;
	}

	/**
	 * The date/time of the event in GMT (that is, UTC) time
	 * 
	 * @return eventDateLocal
	 */
	public String getEventDateLocal() {
		return eventDateLocal;
	}

	/**
	 * Sets the date/time of the event in GMT (that is, UTC) time
	 * 
	 * @param eventDateLocal
	 */
	public void setEventDateLocal(String eventDateLocal) {
		this.eventDateLocal = eventDateLocal;
	}

	/**
	 * The C source file from which the event was fired
	 * 
	 * @return eventCallingFile
	 */
	public String getEventCallingFile() {
		return eventCallingFile;
	}

	/**
	 * Sets the C source file from which the event was fired
	 * 
	 * @param eventCallingFile
	 */
	public void setEventCallingFile(String eventCallingFile) {
		this.eventCallingFile = eventCallingFile;
	}

	/**
	 * The name of the function that fired this event
	 * 
	 * @return eventCallingFunction
	 */
	public String getEventCallingFunction() {
		return eventCallingFunction;
	}

	/**
	 * Sets the name of the function that fired this event
	 * 
	 * @param eventCallingFunction
	 */
	public void setEventCallingFunction(String eventCallingFunction) {
		this.eventCallingFunction = eventCallingFunction;
	}

	/**
	 * The exact line number of the C source file where this event was fired
	 * 
	 * @return eventCallingLineNumber
	 */
	public Integer getEventCallingLineNumber() {
		return eventCallingLineNumber;
	}

	/**
	 * The exact line number of the C source file where this event was fired
	 * 
	 * @param eventCallingLineNumber
	 */
	public void setEventCallingLineNumber(Integer eventCallingLineNumber) {
		this.eventCallingLineNumber = eventCallingLineNumber;
	}

	/**
	 * The date when the event was received by SendVox
	 * 
	 * @return dateReceived
	 */
	public Date getDateReceived() {
		return dateReceived;
	}

	/**
	 * Sets the date when the event was received by SendVox
	 * 
	 * @param dateReceived
	 */
	public void setDateReceived(Date dateReceived) {
		this.dateReceived = dateReceived;
	}

	/**
	 * By default this is the ipv4 address of FreeSWITCH
	 * 
	 * @return freeSWITCHIPv4
	 */
	public String getFreeSwitchIPv4() {
		return freeSwitchIPv4;
	}

	/**
	 * Sets the default ipv4 address of FreeSWITCH server
	 * 
	 * @param freeSWITCHIPv4
	 */
	public void setFreeSwitchIPv4(String freeSwitchIPv4) {
		this.freeSwitchIPv4 = freeSwitchIPv4;
	}

	/**
	 * @return the freeSwitchIPv6
	 */
	public String getFreeSwitchIPv6() {
		return freeSwitchIPv6;
	}

	/**
	 * @param freeSwitchIPv6
	 *            the freeSwitchIPv6 to set
	 */
	public void setFreeSwitchIPv6(String freeSwitchIPv6) {
		this.freeSwitchIPv6 = freeSwitchIPv6;
	}

	/**
	 * @return the eventDateGMT
	 */
	public String getEventDateGMT() {
		return eventDateGMT;
	}

	/**
	 * @param eventDateGMT
	 *            the eventDateGMT to set
	 */
	public void setEventDateGMT(String eventDateGMT) {
		this.eventDateGMT = eventDateGMT;
	}

	/**
	 * @return the eventDateTimestamp
	 */
	public String getEventDateTimestamp() {
		return eventDateTimestamp;
	}

	/**
	 * @param eventDateTimestamp
	 *            the eventDateTimestamp to set
	 */
	public void setEventDateTimestamp(String eventDateTimestamp) {
		this.eventDateTimestamp = eventDateTimestamp;
	}

	private ChannelHandlerContext ctx;
	private Channel channel;

	public void setChannelHandlerContext(ChannelHandlerContext ctx) {
		this.ctx = ctx;
		this.setChannel(ctx.getChannel());
	}

	public ChannelHandlerContext getChannelHandlerContext() {
		return ctx;
	}

	public void setChannel(Channel channel) {
		this.channel = channel;
	}

	public Channel getChannel() {
		return channel;
	}

}